package com.haixiaoke.saas.enterprise.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.contract.domain.LesseeSource;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.contract.service.ILesseeSourceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 租客来源Controller
 *
 * @author panda
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/enterprise/contract/lesseeSource")
public class EnterpriseLesseeSourceController extends BaseController {
    @Autowired
    private ILesseeSourceService lesseeSourceService;

    /**
     * 查询租客来源列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:list')")
    @GetMapping("/page")
    @TenantScope
    public TableDataInfo page(LesseeSource lesseeSource) {
        startPage();
        lesseeSource.setTenantId(TenantContext.getTenantId());
        List<LesseeSource> list = lesseeSourceService.selectLesseeSourceList(lesseeSource);
        return getDataTable(list);
    }

    @GetMapping("/list")
    @TenantScope
    public AjaxResult list(LesseeSource lesseeSource) {
        lesseeSource.setTenantId(TenantContext.getTenantId());
        List<LesseeSource> list = lesseeSourceService.selectLesseeSourceList(lesseeSource);
        return success(list);
    }

    /**
     * 导出租客来源列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:export')")
    @Log(title = "租客来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LesseeSource lesseeSource) {
        List<LesseeSource> list = lesseeSourceService.selectLesseeSourceList(lesseeSource);
        ExcelUtil<LesseeSource> util = new ExcelUtil<LesseeSource>(LesseeSource.class);
        util.exportExcel(response, list, "租客来源数据");
    }

    /**
     * 获取租客来源详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:query')")
    @GetMapping(value = "/{lesseeSourceId}")
    public AjaxResult getInfo(@PathVariable("lesseeSourceId") Long lesseeSourceId) {
        return success(lesseeSourceService.selectLesseeSourceByLesseeSourceId(lesseeSourceId));
    }

    /**
     * 新增租客来源
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:add')")
    @Log(title = "租客来源", businessType = BusinessType.INSERT)
    @PostMapping
    @TenantScope
    public AjaxResult add(@RequestBody LesseeSource lesseeSource) {
        lesseeSource.setTenantId(TenantContext.getTenantId());
        lesseeSource.setCreateBy(getUsername());
        return toAjax(lesseeSourceService.insertLesseeSource(lesseeSource));
    }

    /**
     * 修改租客来源
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:edit')")
    @Log(title = "租客来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LesseeSource lesseeSource) {
        lesseeSource.setUpdateBy(getUsername());
        return toAjax(lesseeSourceService.updateLesseeSource(lesseeSource));
    }

    /**
     * 删除租客来源
     */
    @PreAuthorize("@ss.hasPermi('enterprise:lesseeSource:remove')")
    @Log(title = "租客来源", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lesseeSourceIds}")
    public AjaxResult remove(@PathVariable Long[] lesseeSourceIds) {
        return toAjax(lesseeSourceService.softDeleteLesseeSourceByLesseeSourceIds(lesseeSourceIds));
    }
}
